package org.example.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.domain.Order;
import org.example.model.OrderConfirmParam;
import org.example.model.Result;
import org.example.service.OrderService;
import org.example.vo.OrderStatusCount;
import org.example.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags="微信小程序订单接口管理")
@RequestMapping("p/myOrder")
@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;


    @ApiOperation("查询会员订单各状态数量")
    @GetMapping("orderCount")
    public Result<OrderStatusCount> loadMemberOrderStatusCount(){
        OrderStatusCount orderStatusCount= orderService.queryMemberOrderStatusCount();
        return Result.success( orderStatusCount);
    }

    @ApiOperation("分页查询会员订单列表")
    @GetMapping("/myOrder")
    public Result<Page<Order>> loadMemberOrderPage(@RequestParam Long current,
                                                   @RequestParam Long size,
                                                   @RequestParam Long status) {
        Page<Order> page = orderService.queryMemberOrderPage(current, size, status);
        return Result.success( page);
    }

    @ApiOperation("根据订单编号查询订单详情")
    @GetMapping("/orderDetail")
    public Result<Order> loadMemberOrderDetail(@RequestParam String orderNumber) {
        Order order = orderService.queryMemberOrderDetailByOrderNumber(orderNumber);
        return Result.success( order);
    }

    @ApiOperation("会员确认收货")
    @PutMapping("/receipt/{orderNumber}")
    public Result<String> receiptMemberOrder(@PathVariable String orderNumber) {
        Boolean receipted = orderService.receiptMemberOrder(orderNumber);
        return Result.handle( receipted);
    }

    @ApiOperation("删除会员订单")
    @DeleteMapping("{orderNumber}")
    public Result<String> removeMemberOrder(@PathVariable String orderNumber){

        Boolean removed = orderService.removeMemberOrderByOrderNumber(orderNumber);
        return Result.handle(removed);
    }

    @ApiOperation("查询订单物流情况")
    @GetMapping("/delivery")
    public Result<Map<String,Object>> deliverCheckMemberOrder(@RequestParam String orderNumber){

        Map<String,Object> delivery = orderService.deliverCheckMemberOrderByOrderNumber(orderNumber);
        return Result.success(delivery);
    }

    @ApiOperation("查询会员确认订单页面数据")
    @PostMapping("/confirm")
    public Result<OrderVo> loadMemberOrderConfirmVo(@RequestBody OrderConfirmParam orderConfirmParam) {
        OrderVo orderVo = orderService.queryMemberOrderConfirmVo(orderConfirmParam);
        return Result.success( orderVo);
    }

    @ApiOperation("会员提交订单")
    @PostMapping("/submit")
    public Result<String> submitOrder(@RequestBody OrderVo orderVo) {
        String orderNumber = orderService.submitOrder(orderVo);
        return Result.success(orderNumber);
    }


}
